package com.chenfan.filestore.repository;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chenfan.filestore.model.Task;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;

import java.util.List;
import java.util.Map;

/**
 * 任务表(Task)表数据库访问层
 *
 * @author Leo
 * @since 2023-04-27 11:46:11
 */
public interface TaskDao extends BaseMapper<Task> {

    @Select("select count(*) from ("+"${sql}"+") as t")
    @ResultType(Long.class)
    @InterceptorIgnore(tenantLine = "true")
    Long findByCount(@Param("sql") String sql);

    @Select("${sql}")
    @Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize = 10000)
    @ResultType(Map.class)
    @InterceptorIgnore(tenantLine = "true")
    void findByBatch(@Param("sql") String sql, ResultHandler handler);
}

